<!DOCTYPE html>
<!--suppress ALL -->
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include/head::commonHeaderCustomEdit((${paperId}?'生成试卷':'修改试卷信息'),~{::style})">
    <style type="text/css">
        [v-cloak] {
            display: none;
        }

        .error {
            color: red;
            border-color: red;
        }

        .error:focus {
            color: red;
            border-color: red;
        }

        .error-border {
            border: solid red 1px !important;
        }

        .red {
            color: red;
        }

        body {
            overflow-x: hidden;
        }

        .textbookArea {
            margin-left: 10%;
            padding: 20px;
            background: #f3f4f5;
            margin-bottom: 10px;
        }

        .btn-add-textbook {
            margin-left: 10px;
            width: 100%;
            border: none;
        }

        .btn-add-textbook:hover {
            border: none;
        }

        /* #region 拖拽样式*/
        .draggable-wrap {
            padding: 6px 10px;
            border: 1px dashed #eee;
        }

        .draggable-item {
            margin: 10px;
            background: #4cae4c;
            color: #fff;
            padding: 6px 20px;
            border-radius: 6px;
        }

        /* #endregion 拖拽样式*/

        .sp_result_area {
            width: 400px !important;
        }
    </style>
<body>
<link rel="stylesheet" type="text/css" th:href="@{/static/lib/selectpage/selectpage.css}"/>
<div id="content" class="ch-container">
    <div class="row">
        <div class="col-lg-11 col-sm-11" style="width:93%;margin:0 2%;">
            <div class="row">
                <form class="form-horizontal" method="post" onsubmit="return false;">
                    <div class="box col-md-12">
                        <legend style="padding-bottom:15px;" contenteditable="false">试卷信息</legend>
                        <div id="dataArea">
                            <ul>
                                <li>
                                    <div class="form-group">
                                        <label class="control-label col-sm-2"><i class="red">*</i>试卷标题:</label>
                                        <div class="col-sm-10">
                                            <input class="form-control" id="paperName" name="paperName" type="text" data-toggle="tooltip" data-placement="top" title="请输入试卷标题" placeholder="请输入试卷标题" th:value="${paper.paperName}" required/>
                                            <p class="message error hide">错误信息</p>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <div class="form-group">
                                        <label class="control-label col-sm-2"><i class="red">*</i>试卷类型:</label>
                                        <div class="col-sm-4">
                                            <select th:field="*{paper.tpaperTypeId}" class="form-control" required>
                                                <option value="" selected>-试卷类型-</option>
                                                <option th:each="list:${listPaperType}" th:value="${list.id}" th:text="${list.cnName}"></option>
                                            </select>
                                        </div>
                                        <label class="control-label col-sm-2"><i class="red">*</i>难度系数:</label>
                                        <div class="col-sm-4">
                                            <select th:field="*{paper.qddegreeId}" class="form-control" required>
                                                <option value="" selected>-难度系数-</option>
                                                <option th:each="list:${listQDifficultyDegree}" th:value="${list.id}" th:text="${list.cnName}"></option>
                                            </select>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <div class="form-group">
                                        <label class="control-label col-sm-2"><i class="red">*</i>选择年级:</label>
                                        <div class="col-sm-4">
                                            <select class="form-control" th:field="*{paper.gradeId}" required>
                                                <option value="" selected>-年级-</option>
                                                <option th:each="list:${listQGrade}" th:value="${list.id}" th:text="${list.cnName}"></option>
                                            </select>
                                        </div>
                                        <label class="control-label col-sm-2"><i class="red">*</i>选择学期:</label>
                                        <div class="col-sm-4">
                                            <select id="term" name="term" class="form-control" required>
                                                <option value="" selected>-学期-</option>
                                                <option value="1" th:selected="${paper.term==1}">上学期</option>
                                                <option value="2" th:selected="${paper.term==2}">下学期</option>
                                            </select>
                                        </div>
                                    </div>
                                </li>
                                <li class="textbookArea">
                                    <span style="cursor:pointer;padding: 10px 0;">教材与页码</span>
                                    <a onclick="hidestate($(this))" class="itemhide" hidestate="0" style="float:right;cursor:pointer;">收缩</a>
                                    <div id="textbookList" class="textbookList">
                                        <div id="textbookItem1" class="textbookItem">
                                            <i onclick="deletetbitem($(this))" style="cursor:pointer;padding: 10px 0;" class="glyphicon glyphicon-remove"></i>
                                            <div class="form-group">
                                                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择教材</div>
                                                <div class="col-md-10 col-xs-9 item">
                                                    <input class="form-control" type="text" placeholder="请选择关联教材" id="relatedTextbooks1" name="relatedTextbooks1">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择页码</div>
                                                <div class="col-md-10 col-xs-9 item">
                                                    <input class="form-control" id="page1" name="page1" type="text" placeholder="请选择教材页码，可多选"/>
                                                    <p class="message error hide">错误信息</p>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择单元</div>
                                                <div class="col-md-10 col-xs-9 item">
                                                    <select id="unit1" name="unit1" class="form-control">
                                                        <option value="" selected>-单元-</option>
                                                        <option th:each="list:${listQuestionTerm}" th:value="${list.id}" th:text="${list.cnName}"></option>
                                                    </select>
                                                    <p class="message error hide">错误信息</p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <span class="col-md-2 col-xs-3 text-left">
                                            <button id="btn-add-textbook" class="btn btn-info btn-add-textbook"><span>添加教材</span></button>
                                        </span>
                                    </div>
                                </li>
                            </ul>
                            <div id="quesbank">

                                <!--#region 拖拽-->
                                <div class="draggable-wrap" v-show="listQuestionItems.length">
                                    <h4>按住一项可拖拽进行排序</h4>
                                    <draggable v-model="listQuestionItems">
                                        <div
                                                v-for="(item, index) in listQuestionItems"
                                                v-if="item"
                                                :key="index"
                                                class="draggable-item">
                                            序号：{{index + 1}} 大题标题：{{item.questionTitle}}
                                        </div>
                                    </draggable>
                                </div>
                                <!--#endregion 拖拽-->

                                <ul v-for="(questionItem,qiIdx) in listQuestionItems" v-cloak>
                                    <li>
                                        <div class="col-sm-12">
                                            <label class="control-label col-sm-2">大题标题:</label>
                                            <input type="hidden" :name="'listQuestionItems[' + qiIdx + '].questionTitle'" v-bind:value="questionItem.questionTitle">
                                            <label class="control-label col-sm-9" style="text-align: left;">{{questionItem.questionTitle}}</label>
                                            <label class="control-label col-sm-1" style="text-align: right;cursor: pointer;" v-on:click="delQues(qiIdx)">X</label>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="col-sm-12"
                                             v-for="(questionBank,qbIdx) in questionItem.listQuestionBanks">
                                            <label class="control-label col-sm-2"></label>
                                            <div class="col-sm-10">
                                                <ul>
                                                    <li>
                                                        <input type="hidden" :name="'listQuestionItems[' + qiIdx + '].listQuestionBanks['+ qbIdx +'].id'" v-bind:value="questionBank.id">
                                                        【{{questionBank.id}}】 {{questionBank.title}}
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="box col-md-12">
                        <fieldset style="text-align: center;">
                            <legend contenteditable="false"></legend>
                            <button class="btn btn-success" type="submit" onclick="submitForm(this);" id="btnSubmit" data-loading-text="加载中..." style="margin:0 20px;">提交</button>
                            <a th:class="${paperId}?'btn btn-primary hide':'btn btn-primary'" id="addQuesItem" href="javascript:void(0);">选择题目</a>
                        </fieldset>
                    </div>
                </form>
                <!--/form-->
            </div>
            <!--/row-->
        </div>
        <!--/#content.col-->
    </div>
    <!--/fluid-row-->
</div>
<!-- content ends -->

<!-- template -->
<div id="textbookItemTemplate" class="hide">
    <div id="textbookItem" class="textbookItem">
        <i onclick="deletetbitem($(this))" style="cursor:pointer;padding: 10px 0;" class="glyphicon glyphicon-remove"></i>
        <div class="form-group">
            <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择教材</div>
            <div class="col-md-10 col-xs-9 item">
                <input class="form-control relatedTextbooks" type="text" placeholder="请选择关联教材" id="relatedTextbooks" name="relatedTextbooks">
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择页码</div>
            <div class="col-md-10 col-xs-9 item">
                <input class="form-control page" id="page" name="page" type="text" placeholder="请选择教材页码，可多选"/>
                <p class="message error hide">错误信息</p>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-1 col-xs-2 text-right title"><i class="red">*</i>选择单元</div>
            <div class="col-md-10 col-xs-9 item">
                <select id="unit" name="unit" class="form-control unit">
                    <option value="" selected>-单元-</option>
                    <option th:each="list:${listQuestionTerm}" th:value="${list.id}" th:text="${list.cnName}"></option>
                </select>
                <p class="message error hide">错误信息</p>
            </div>
        </div>
    </div>
</div>

<div th:include="include/onload_js::onloadJSCustomEdit(~{::script})">
    <script type="text/javascript" src="../../static/js/vue.min.js" th:src="@{/static/js/vue.min.js}"></script>
    <!--#endregion 拖拽组件-->
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.7.0/Sortable.min.js"></script>
    <script src="https://hnres.etalk365.com/public/lib/Vue.Draggable/2.23.2/vuedraggable.umd.min.js"></script>
    <!--#endregion 拖拽组件-->
    <script src="https://hnres.etalk365.com/public/lib/Vue.Draggable/2.23.2/vuedraggable.umd.min.js"></script>
    <script type="text/javascript" th:src="@{'/static/lib/selectpage/selectpage.js?v=201901250003'}"></script>
    <script type="text/javascript" th:inline="javascript">
        var ADMIN_TOKEN_STRING = "S6AsGHLhri4-VJyGrBfPsbEpD56SNSTScoolBwW7QTbpa65H-QbKisyjsEf9TD1WneWUxynXB7VupWEZWkCQ-A";

        var currentTextbookIndex = 1;

        /*<![CDATA[*/
        var paperId = /*[[${paperId}]]*/0;
        var relateTextbookString = /*[[${paper.textbooksIdString}]]*/0;
        var address = /*[[${paper.address}]]*/'';
        var relatePageString = /*[[${paper.pageString}]]*/'';
        var unitString = /*[[${paper.unitIdString}]]*/'';
        // noinspection SuspiciousTypeOfGuard
        var relateTextbookArray = (relateTextbookString == null || relateTextbookString == "") ? [] : relateTextbookString.split(",");
        var addressArray = (address == null || address == "") ? [] : address.split(",");
        var pagesArray = (relatePageString == null || relatePageString == "") ? [] : relatePageString.split(",");
        var unitArray = (unitString == null || unitString == "") ? [] : unitString.split(",");
        /*]]>*/

        console.log("relateTextbookArray:" + JSON.stringify(relateTextbookArray));

        var ADD = "add";
        var EDIT = "edit";
        var actionType = paperId > 0 ? EDIT : ADD;

        var app = new Vue({
            el: '#content',
            data: {
                cnName: "",
                typeCnName: "",
                degreeCnName: "",
                gradeCnName: "",
                listQuestionItems: []
            },
            methods: {
                delQues: function (qIdx) {
                    // var p = $(obj).parent().parent();
                    // var n = $(p).next();
                    // $(n).remove();
                    // $(p).remove();
                    //删除当前数据
                    app.listQuestionItems.splice(qIdx, 1);
                }
            }
        });

        $(function () {
            $("#addQuesItem").on("click", function () {
                var url = "/testPaper/page/chooseQuestion";
                //iframe窗口
                layer.open({
                    type: 2,
                    title: false,
                    closeBtn: 1, //显示关闭按钮
                    // shade: [0],
                    shade: 0.4,
                    area: ['90%', '90%'],
                    //offset: 'rb', //右下角弹出
                    // time: 2000, //2秒后自动关闭
                    // anim: 2,
                    content: [url, 'yes'], //iframe的url，no代表不显示滚动条
                    end: function () { //此处用于演示
                    }
                });
            });

            // 添加教材和页码
            $("#btn-add-textbook").on("click", function (e) {
                e.preventDefault();

                // 组件ID增加
                // console.log("currentTextbookIndex before:" + currentTextbookIndex);
                currentTextbookIndex = currentTextbookIndex + 1;
                // console.log("currentTextbookIndex after:" + currentTextbookIndex);

                // 设置模板ID
                var template = $("#textbookItemTemplate").find(".textbookItem").eq(0).clone();
                $(template).attr("id", "textbookItem" + currentTextbookIndex);

                // console.log("template before:" + $(template).html());

                var tb = $(template).find(".relatedTextbooks").eq(0);
                $(tb).attr("id", "relatedTextbooks" + currentTextbookIndex);
                $(tb).attr("name", "relatedTextbooks" + currentTextbookIndex);

                var pg = $(template).find(".page").eq(0);
                $(pg).attr("id", "page" + currentTextbookIndex);
                $(pg).attr("name", "page" + currentTextbookIndex);

                var ut = $(template).find(".unit").eq(0);
                $(ut).attr("id", "unit" + currentTextbookIndex);
                $(ut).attr("name", "unit" + currentTextbookIndex);

                //  console.log("template after:" + $(template).html());

                $("#textbookList").append(template);

                // 初始化
                initAdd(currentTextbookIndex);
            });

            // 数据初始化
            initPage();

            function valiForm() {
                //表单验证
                $('form').validate({
                    focusInvalid: true,
                    errorPlacement: function (error, element) {
                        var errorMsg = error[0].innerHTML;
                        var elem = element[0];
                        $(elem).next('.message').removeClass("hide").addClass("error").html(errorMsg).show();
                    },
                    success: function (element) {
                        var elem = $(element)[0].htmlFor;
                        $(elem).next('.message').hide();
                    }
                });
            }
        });

        /**
         * 获取知识点详情
         */
        function initPage() {
            console.log("init page");
            if (actionType == ADD) {
                initAdd(1);
            } else {
                // 开启加载层
                layer.load(2, {
                    shade: [0.6, '#fff'], content: '数据加载中...', success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '6px',
                            'width': '150px',
                            'padding-left': '40px'
                        });
                        layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                            'width': '150px !important',
                            'background-position': '2px 0 !important'
                        });
                    }
                });
                initEdit();
            }
        }

        function initAdd(index) {
            console.log("init Add,index:" + index);
            //关联教材
            $('#relatedTextbooks' + index).selectPage({
                showField: 'name',
                keyField: 'id',
                data: '/questionKnowledge/showTextbooks',
                multiple: false,//单选
                pageSize: 5,
                eAjaxSuccess: function (data) {
                    // console.log("data:" + JSON.stringify(data));
                    return data;
                },
                eSelect: function (data) {
                    changeMaterial(data.address, index, "", "");
                }
            });

            // 录入校验
            $("#relatedTextbooks" + index + "_text").on('blur', function () {
                var relatedTextbooksObj = $("#relatedTextbooks" + index);
                if (relatedTextbooksObj.val() === '') {
                    relatedTextbooksObj.parent().addClass("error");
                    relatedTextbooksObj.parent().addClass("error-border");
                } else {
                    relatedTextbooksObj.parent().removeClass("error");
                    relatedTextbooksObj.parent().removeClass("error-border");
                }
            });

            // 教材页码
            $('#page' + index).selectPage({
                showField: 'name',
                keyField: 'id',
                data: {},
                multiple: false,//关闭多选
                maxSelectLimit: 0,//无限制页码
                pageSize: 5,
                // eAjaxSuccess: function (data) {
                //     return data;
                // },
                eSelect: function (data) {
                    // console.log("page_text:" + $('#page' + index).selectPageText());
                }
            });

            $("#page" + index + "_text").on('blur', function () {
                var pageObj = $("#page" + index);
                if (pageObj.val() === '') {
                    pageObj.parent().addClass("error");
                } else {
                    pageObj.parent().removeClass("error");
                }
            });
        }

        function initEdit() {
            // 教材初始化

            // ==设置第一个
            // 初始化控件
            initAdd(1);

            if (relateTextbookArray.length > 0) {
                // ==设置剩下的
                for (var idx in relateTextbookArray) {
                    if (idx > 0) {//跳过第一个
                        // 初始化控件
                        $("#btn-add-textbook").click();
                    }

                    // 设置教材
                    var otherTextbookObj = $("#relatedTextbooks" + currentTextbookIndex);
                    otherTextbookObj.val(relateTextbookArray[idx]);
                    otherTextbookObj.selectPageRefresh();

                    // 设置页码
                    changeMaterial(addressArray[idx], currentTextbookIndex, pagesArray[idx], unitArray[idx]);
                }
            } else {
                //关闭加载层
                layer.closeAll('loading');
            }
        }

        function changeMaterial(address, index, currentPage, currentUnit) {
            if (address != null && address !== "") {
                console.log("changeMaterial->,address:" + address + ",index:" + index + ",currentPage:" + currentPage + ",currentUnit:" + currentUnit);
                // $("#viewcover").find("img").attr("src","//hkmaterials.etalk365.com/"+address+"/1.png");
                if (address.lastIndexOf("/") === address.length - 1) {
                    address += "cfg.json";
                } else {
                    address += "/cfg.json";
                }
                $.ajax({
                    type: 'get',
                    url: "/questionKnowledge/showTextbooksPages",
                    data: {'strUrl': address},
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        // console.log(JSON.stringify(data));
                        if (data.list != null && data.list !== "") {
                            // $("#viewcover").show();
                            var pages = data.list;
                            // console.log("pages:" + JSON.stringify(pages));
                            // if (pages.length == 0) {
                            //     changeMaterial(address, index, currentPage, currentUnit)
                            //     return;
                            // }
                            var pageObj = $('#page' + index);
                            pageObj.selectPageData(pages);

                            // 当前页码
                            pageObj.val(currentPage);
                            pageObj.selectPageRefresh();

                            var unitObj = $('#unit' + index);
                            unitObj.val(currentUnit);

                            console.log("currentTextbookIndex:" + currentTextbookIndex);
                            if (currentTextbookIndex === relateTextbookArray.length) {
                                //关闭加载层
                                layer.closeAll('loading');
                            }
                        }
                    }
                });
            }
        }

        /*
         * 删除教材页码
         *
         */
        function deletetbitem(domthis) {
            if (domthis.parents('.textbookList').find('.textbookItem').length > 1) {
                domthis.parent('.textbookItem').eq(0).remove();
            }
        }

        /*
         * 收缩展开教材页码
         *
         */
        function hidestate(domthis) {
            // console.log("hidestate:" + domthis.attr('hidestate'));
            if (domthis.attr('hidestate') === '0') {
                domthis.attr('hidestate', '1');
                domthis.text('展开');
                $('#textbookList').hide('fast');
            } else {
                domthis.attr('hidestate', '0');
                domthis.text('收缩');
                $('#textbookList').show('fast');
            }
        }

        function reloadQuestionDataForPaper(questionTitle, qids) {
            $("#btnSubmit").button('loading');
            $.post("/question/detailList", {questionIds: qids.join(",")}, function (res) {
                $("#btnSubmit").button('reset');
                console.log(JSON.stringify(res));
                if (res != null && res.status == 1) {

                    //将传过来的id集合转换成小题题目
                    var questionBanks = new Array();

                    for (var idx in res.data) {
                        var qb = res.data[idx];
                        console.log("小题：ID=" + qb.id);
                        questionBanks.push(qb);
                    }

                    var questionItem = {
                        questionTitle: questionTitle,
                        listQuestionBanks: questionBanks
                    }

                    //刷新vue绑定的数据
                    app.listQuestionItems.push(questionItem);
                } else {
                    parent.layer.msg('操作失败', {icon: 2});
                }
            });

        }

        /*
        * 表单校验
        *
        */
        function checkForm(obj) {
            var status = $(obj).valid();
            console.log("vali status:" + status);
            if (!status) {
                //没有通过验证
                $("#btnSubmit").button('reset');
                return false;
            }
            return true;
        }

        /*
         * 提交表单
         *
         */
        function submitForm(obj) {
            $(obj).button('loading');

            var form = $("form");

            //表单校验
            if (!checkForm($(form))) {
                $(obj).button('reset');
                return false;
            }

            var quesCount = $("#quesbank").find("li").length;
            // alert(quesCount);
            if (quesCount == 0 && actionType == ADD) {//添加的时候需要校验有没有添加题目
                $(obj).button('reset');
                layer.msg('必须选择一个大题', {icon: 2});
                return false;
            }

            // 组装教材关联数据
            var textbooksList = [];
            var items = $("#textbookList .textbookItem");
            $(items).each(function (i, v) {
                var cIdx = parseInt(i) + 1;

                var tb = $(v).find("input[name='relatedTextbooks" + cIdx + "']").val();
                var pg = $(v).find("input[name='page" + cIdx + "']").val();
                var pgName = $("#page" + cIdx).selectPageText();
                var unit = $("#unit" + cIdx).val();

                console.log("pid:" + paperId);
                console.log("tb:" + tb);
                console.log("pg:" + pg);
                console.log("pgName:" + pgName);
                console.log("unit:" + unit);

                var newObj = {
                    testPaperId: paperId,
                    textbookId: tb,
                    textbookPage: pg,
                    textbookPageName: pgName,
                    unitId: unit
                };
                if (tb != "" && pg != "" && pgName != "" && unit != "") {
                    textbooksList.push(newObj);
                }
            });

            /** #region 提交之间对拖拽的数据进行排序 */
            var allQuesIdList = [];
            var sortedlistQuestionItems = JSON.parse(JSON.stringify(app.listQuestionItems))
            var cIndex = 0;
            for (var j = 0; j < sortedlistQuestionItems.length; j++) {
                var qlist = sortedlistQuestionItems[j].listQuestionBanks;
                for (var k = 0; k < qlist.length; k++) {
                    qlist[k].sort = cIndex + 1;
                    allQuesIdList.push(qlist[k].id);
                    ++cIndex;
                }
                sortedlistQuestionItems[j].listQuestionBanks = qlist;
            }

            var uniqeQuesList = unique(allQuesIdList);
            // 检测试卷中的题目是否重复
            if (uniqeQuesList.length != allQuesIdList.length) {
                console.log("allQuesIdList:" + JSON.stringify(allQuesIdList));
                layer.msg("试卷中的题目不能重复，请删除重复题目再提交", {icon: 2});
                $(obj).button('reset');
                return;
            }

            /** #region 提交之间对拖拽的数据进行排序 */
            var formData = {
                id: paperId,
                paperName: $.trim($("#paperName").val()),
                tpaperTypeId: $("#tpaperTypeId").val(),
                qddegreeId: $("#qddegreeId").val(),
                gradeId: $("#gradeId").val(),
                term: $("#term").val(),
                textbooksList: textbooksList,
                listQuestionItems: sortedlistQuestionItems
            };
            console.log("post formData:" + JSON.stringify(formData));

            $.ajax({
                type: "post",
                url: "/testPaper/submit?tokenString=" + ADMIN_TOKEN_STRING,
                data: JSON.stringify(formData),
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    $(obj).button('reset');
                    //console.log(JSON.stringify(res));
                    if (res != null && res.status == 1) {
                        parent.layer.msg('操作成功', {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.window.location.reload();
                    } else {
                        parent.layer.msg('操作失败:' + res.msg, {icon: 2});
                    }
                },
                error: function () {
                    $("#submit-button").button('reset');
                    parent.layer.msg('系统异常:', {icon: 2});
                }
            });
        }

        /**
         * 数组去重
         * @param array
         * @returns {*}
         */
        function unique(array) {
            var res = array.filter(function (item, index, array) {
                return array.indexOf(item) === index;
            })
            return res;
        }
    </script>
</div>
</body>
</html>
